import Vue from 'vue'
import request from './request'
import ElementUI from 'element-ui'
import 'xe-utils'
import VXETable from 'vxe-table'
import '@/assets/styles/custom.scss'
import BKFittings from 'bk-fittings'
import DataSourceChart from '@/views/business/ysqgzt/platform/components/dataSource-chart/main.vue'
import 'bk-fittings/dist/bk-fittings.css'
// import BKFittings from '../../../../product/bk-fittings/packages'
import 'remixicon/fonts/remixicon.css'
import Auth from './directives/auth'
import Append from './directives/append'
import '@/icons'
import permissions from './permissions'
import Chart from '@/components/chart'
import ImagePreviewer from '@/components/image-previewer'
import SegmentUpload from '@/components/segment-upload'
import Settings from '@/components/settings'
import PasswordPanel from '@/components/password-panel'
import InfiniteScroll from '@/components/infinite-scroll'
import mapManager from './map-manager'
import helper from './helper'
import { includeMap } from '@/configs'
// import BKAnalysisMaker from '../../../bk-analysis-maker/packages'
import 'bk-analysis-maker/dist/bk-analysis-maker.css'
const elementMessage = ElementUI.Message

const messages = ['success', 'warning', 'info', 'error']
messages.forEach(type => {
  ElementUI.Message[type] = options => {
    if (typeof options === 'string') {
      options = {
        message: options
      }
      // 默认配置
      options.showClose = true
    }
    options.type = type
    return elementMessage(options)
  }
})

Vue.directive('auth', Auth)
Vue.directive('append', Append)
Vue.use(ElementUI)
Vue.use(VXETable)
Vue.use(InfiniteScroll)

Vue.use(BKFittings, {
  Dictionary: {
    url: '/dic/getDicData',
    cacheEnabled: true,
    propMap: {
      key: 'dicKey'
    },
    dataHandler: (data) => {
      return data.rows
    }
  },
  Table: {
    pagerLayout: ['PrevJump', 'PrevPage', 'JumpNumber', 'NextPage', 'NextJump', 'Sizes', 'Total'],
    pageSize: 20,
    propMap: {
      pageSize: 'pageSize',
      currentPage: 'pageNum',
      total: 'total',
      data: 'rows'
    }
  },
  Tree: {
    requestMethod: {
      data: 'post'
    }
  },
  Upload: {
    url: '/file/uploads'
  }
})
window.$request = Vue.prototype.$request = request
window.$permission = Vue.prototype.$permission = permissions
window.$mapManager = Vue.prototype.$mapManager = mapManager
window.$helper = Vue.prototype.$helper = helper
window.$fittingUtils = Vue.prototype.$utils

// 以下代码禁止修改
// 加载布局
const requireLayout = require.context('../../../bk-web-foundation/src/layouts', true, /\.vue$/)
requireLayout.keys().forEach((fileName) => {
  const componentConfig = requireLayout(fileName)
  const componentName = componentConfig.default.name
  Vue.component(componentName, componentConfig.default || componentConfig)
})

// 加载组件
const requireComponent = require.context('../../../bk-web-foundation/src/components', true, /\.vue$/)
requireComponent.keys().forEach((fileName) => {
  const componentConfig = requireComponent(fileName)
  const componentName = componentConfig.default.name
  Vue.component(componentName, componentConfig.default || componentConfig)
})
Vue.component('BKDataSourceChart', DataSourceChart)
Vue.component('BKChart', Chart)
Vue.component('BKImagePreviewer', ImagePreviewer)
Vue.component('BKSegmentUpload', SegmentUpload)
Vue.component('BKSettings', Settings)
Vue.component('BKPasswordPanel', PasswordPanel)
Vue.component('BKLayoutPicture', () => import('@/views/business/ysqxx/layout.vue'))

if (includeMap) {
  Vue.component('BKGeoMap', () => import('@/components/geo-map'))
}
